package com.party.web.web.controller.testc;

import com.party.common.constant.Constant;
import com.party.core.model.notify.Instance;
import com.party.core.model.system.TargetType;
import com.party.core.service.member.IPackageCountService;
import com.party.notify.jms.publisher.service.INotifyPublisherService;
import com.party.notify.sms.model.SmsMessage;
import com.party.notify.sms.service.ISmsService;
import com.party.notify.template.service.impl.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/testc")
public class TestController {
	@Autowired
	public TemplateService templateService;


	@RequestMapping(value = "form")
	public ModelAndView form() {
		ModelAndView mv = new ModelAndView("test/form_test");
		return mv;
	}

	@RequestMapping(value = "phoneView")
	public ModelAndView phoneView() {
		ModelAndView mv = new ModelAndView("test/phone_view");
		return mv;
	}

	@Autowired
	private ISmsService smsService;

	@Autowired
	private IPackageCountService packageCountService;


	@Autowired
	private INotifyPublisherService notifyPublisherService;


	@ResponseBody
	@RequestMapping("test1")
	public void test1() {


		for (int i = 0; i < 1000; i++) {

			// 根据事项找到模板
			String massage = "我的发";

			//添加签名
			String partnerName = "同行者测试test8同行者测试账号";
			massage = templateService.smsSign(massage, partnerName);
			SmsMessage smsMessage = new SmsMessage();
			smsMessage.setContent(massage);
			smsMessage.setTelephone("18124081240");
			smsMessage.setMemberId("ORGANIZATION");
			smsMessage.setTargetId("949b34062d7e4ce685421df3889e6319");
			smsMessage.setWay("0ea777250ec74405821ea15a35e14401");
			smsMessage.setTemplateId("035e315880314de5b69c9cef7be02995");
			smsMessage.setIsNewFlag(1);
			smsMessage.setIsPermitFlag(1);

			//短信写入
			String id = smsService.write(smsMessage);
			smsMessage.setId(id);

			try {
				if (Instance.FLAG_YES.equals(smsMessage.getIsNewFlag())) {
					packageCountService.updateUseCount(smsMessage.getMemberId(), TargetType.PUSH_SMS.getCode());
				}
			} catch (Exception e) {

			}

			try {
				notifyPublisherService.send(smsMessage, Constant.MESSAGE_CHANNEL_SMS, true);
			} catch (Exception e) {

			}
		}
	}
}
